package com.bwie.parkdemo.mvvm.model.entity;

import android.text.TextUtils;

import com.bwie.lib_core.base.BaseEntity;
import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;

import java.util.ArrayList;
import java.util.List;

/**
 * 全部访客申请列表->由于服务器接口添加token
 * swagger文档无法拼接token
 * 访问测试->现请求一次获取服务器返回json在进行相关解析操作
 *{"msg":"成功","values":"[{\"carNum\":\"string\",
 * \"parkId\":50,
 * \"userId\":48,
 * \"visitorDescribe\":\"string\",
 * \"visitorEnd\":\"0\",\"visitorId\":47,
 * \"visitorStart\":\"0\",\"visitorTime\":\"0\"},{\"carNum\":\"string\",\"parkId\":50,\"userId\":48,\"visitorDescribe\":\"string\",\"visitorEnd\":\"0\",\"visitorId\":48,\"visitorStart\":\"0\",\"visitorTime\":\"0\"},{\"carNum\":\"string\",\"parkId\":50,\"userId\":48,\"visitorDescribe\":\"string\",\"visitorEnd\":\"0\",\"visitorId\":49,\"visitorStart\":\"0\",\"visitorTime\":\"0\"}]","statuesCode":"200"}
 * */
public class VisitorEntity extends BaseEntity {

    public String values;
    private List<Object>datas;

    public List<Object> getDatas() {
        if (datas == null){
            datas = new ArrayList<>();
            if (TextUtils.isEmpty(values))
                return datas;
            JSONArray jsonArray = null;
            try {
                jsonArray = new JSONArray(values);
                for (int i = 0;i < jsonArray.length();i ++){
                    String jobStr = jsonArray.getJSONObject(i).toString();
                    Values values = new Gson().fromJson(jobStr,Values.class);
                    datas.add(values);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return datas;
    }

    public static class Values{
        public String carNum;
        public String parkId;
        public String userId;
        public String visitorDescribe;
        public String visitorEnd;
        public String visitorId;
        public String visitorStart;
        public String visitorTime;
    }

}
